package cn.com.bluemoon.daps.api.sys.factory;

import cn.com.bluemoon.daps.api.sys.RemoteSystemUserService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiSystem;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.system.dto.SystemUserDto;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RemoteSystemUserServiceFallbackFactory implements FallbackFactory<RemoteSystemUserService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSystemUserServiceFallbackFactory.class);


    @Override
    public RemoteSystemUserService create(Throwable throwable) {
        log.error("系统用户服务调用失败:{}", throwable.getMessage());
        return new RemoteSystemUserService() {
            /**
             * 1
             *
             * @return 获取系统用户列表
             */
            @Override
            public ResultBean<List<SystemUserDto>> list() {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统用户列表失败");
            }

            @Override
            public ResultBean<List<SystemUserDto>> userDba() {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统DBA用户列表失败");
            }

            @Override
            public ResultBean<List<SystemUserDto>> listByAccount(List<String> accounts) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取账号的用户列表失败");
            }
        };
    }
}
